package ThreadDemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-10-09
 * Time: 22:50
 */
public class Demo5 {
    public static void main(String[] args) {
        Thread thread = new Thread("t1") {//创建一个匿名内部类，该类为Thread的子类，但是不知道名字，只能使用一次该子类
            @Override
            public void run(){
                while(true){
                    System.out.println("hello Thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        thread.start();

        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
